﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;

namespace HQWeb.Progect.ProgectManage
{
    /// <summary>
    /// ProgectServer 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    [GenerateScriptType(typeof(Model.Progect.T_PUB_PROJECT))]  //页面注册类
    [GenerateScriptType(typeof(Model.Progect.T_PUB_PROJECTMATERIAL))]
    public class ProgectServer : System.Web.Services.WebService
    {
       
        //添加项目
         [WebMethod(EnableSession = true)]
        public string Add(Model.Progect.T_PUB_PROJECT progetModel, IList<Model.Progect.T_PUB_PROJECTMATERIAL> matralList)
        {
            string resout = "";
            string strGIud = System.Guid.NewGuid().ToString() +"-"+ Session["BRANCH_ID"];
            progetModel.PROJECT_ID = strGIud;
            progetModel.FLAG = true;
            progetModel.TIME = DateTime.Now;
            progetModel.Count = 0;
            foreach (Model.Progect.T_PUB_PROJECTMATERIAL item in matralList)
            {
                item.PROJECT_ID = strGIud;
            }
            BLL.Progect.T_PUB_PROJECT progectBll = new BLL.Progect.T_PUB_PROJECT();
            try
            {
                progectBll.AddProgect(progetModel, matralList);
            }
            catch (Exception ex)
            {

                resout = ex.Message;
            }

            return resout;
        }

        //编辑项目
         [WebMethod]
        public string Edit(Model.Progect.T_PUB_PROJECT progetModel, IList<Model.Progect.T_PUB_PROJECTMATERIAL> matralList)
        {
            string strResout = "";
            BLL.Progect.T_PUB_PROJECT progectBll = new BLL.Progect.T_PUB_PROJECT();
            IList<Model.Progect.T_PUB_PROJECTMATERIAL> addList = new List<Model.Progect.T_PUB_PROJECTMATERIAL>();
            IList<Model.Progect.T_PUB_PROJECTMATERIAL> EditList = new List<Model.Progect.T_PUB_PROJECTMATERIAL>();
            foreach (Model.Progect.T_PUB_PROJECTMATERIAL item in matralList)
            {
                if (item.ID ==0)
                {
                    addList.Add(item);
                }
                else
                {
                    EditList.Add(item);
                }
            }
            try
            {
                progetModel.FLAG = true;
                progectBll.EditProgect(progetModel, EditList, addList);
            }
            catch (Exception ex)
            {

                strResout = ex.Message;
            }

          
            return strResout;
        }

         [WebMethod]

         public Model.Progect.T_PUB_PROJECT progetModel(string strID)
         {
             BLL.Progect.T_PUB_PROJECT progectBll = new BLL.Progect.T_PUB_PROJECT();
             return progectBll.GetModel(strID);
         }
        /// <summary>
        /// 编辑时删除元素
        /// </summary>
        /// <param name="strID"></param>
        /// <returns></returns>
          [WebMethod]
        public string DelprogectY(string strID)
        {
            string strResout = "";
            BLL.Progect.T_PUB_PROJECTMATERIAL bll = new BLL.Progect.T_PUB_PROJECTMATERIAL();
            int temp;
            int.TryParse(strID, out temp);
            try
            {
                bll.Delete(temp);
            }
            catch (Exception ex)
            {

                strResout = ex.Message;
            }

            return strResout;
        }
    }
}
